/*
** my_str_to_wordtab.c for libmyV2 in /home/noret_a//piscine/Jour8
**
** Made by christophe noret
** Login   <noret_a@epitech.net>
**
** Started on  Thu Oct 11 15:01:44 2012 christophe noret
** Last update Thu Oct 11 22:31:53 2012 christophe noret
*/

#include <stdlib.h>

int     count_word(char *str)
{
  int   i;
  int   count;

  i = 0;
  count = 0;
  while (str[i])
    {
      if (str[i] == ' ')
	count++;
      i++;
    }
  return (count);
}

char    **create_tab(char **tab, char *str)
{
  int   i;
  int   line;
  int   col;

  i = 0;
  line = 0;
  col = 0;
  while (str[i])
    {
      if (str[i] == ' ')
        {
          tab[line][col] = '\0';
          line++;
          col = 0;
          i++;
        }
      tab[line][col] = str[i];
      col++;
      i++;
    }
  tab[line + 1] = '\0';
  return (tab);
}

char    **my_str_to_wordtab(char *str)
{
  char **tab;
  int   nb_word;
  int   i;

  i = 0;
  nb_word = count_word(str);
  tab = malloc((nb_word)*sizeof(*tab));
  while (i < nb_word + 1)
    {
      tab[i] = malloc((my_strlen(str))*sizeof(**tab));
      i++;
    }
  return (create_tab(tab, str));
}
